package com.smile.service.job;

import com.alibaba.fastjson.JSONObject;
import com.smile.service.mqtt.handler.AbstractServicesHandler;
import com.smile.service.entity.drc.HeartBeatData;
//import com.xxl.job.core.context.XxlJobHelper;
//import com.xxl.job.core.handler.annotation.XxlJob;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

@Component
public class DeviceJob {

    @Autowired
    private AbstractServicesHandler abstractServicesHandler;

    /**
     * 执行巡警
     *
     */
//    @XxlJob("heartbeat")
//    @Scheduled(fixedRate = 2000)
//    public void executeOnSiteInspection(String param) {
//    public void heartbeat() {
////        System.out.println("测试定时任务");
////        System.out.println("发送drc心跳包");
//        JSONObject jsonObject = new JSONObject();
//        HeartBeatData heartBeatData = new HeartBeatData();
//        heartBeatData.setTimestamp(System.currentTimeMillis());
//        jsonObject.put("method", "heart_beat");
//        System.out.println(jsonObject.toJSONString());
//
//        Date date = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String formattedDate = sdf.format(date);
//        System.out.println(formattedDate);
//        jsonObject.put("data", heartBeatData);
//        try {
//            abstractServicesHandler.process(jsonObject.toJSONString());
//        } catch (MqttException e) {
//            System.out.println(e.getMessage());
//            throw new RuntimeException(e);
//        }
//    }
}
